package cn.zhf.shop.utils;

import cn.zhf.shop.entity.Orders;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class CountOrdersNumberByDays {

    //日期"yyyy-MM-dd"
    public static List<Integer> getArray(List<String> DateList, List<Orders> ordersList){
        List<Integer> integerList = new LinkedList<>();
        for (int i=0;i<DateList.size();i++)
        {
            int number =0;
            String time = DateList.get(i);
            if (ordersList.size()>0)
            {
                for (int j=0;j<ordersList.size();j++)
                {
                    if (ordersList.get(j).getPayTime()!=null)
                    {
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
                        String ordersTime = formatter.format(ordersList.get(j).getPayTime());
                        if (time.equals(ordersTime))
                        {
                            number++;
                        }
                    }

                }
            }

            integerList.add(number);
        }
        return integerList;
    }

    //日期"yyyy-MM"
    public static List<Integer> getArrayMonth(List<String> DateList, List<Orders> ordersList){
        List<Integer> integerList = new LinkedList<>();
        for (int i=0;i<DateList.size();i++)
        {
            int number =0;
            String time = DateList.get(i);
            if (ordersList.size()>0)
            {
                for (int j=0;j<ordersList.size();j++)
                {
                    if (ordersList.get(j).getPayTime()!=null)
                    {
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM");
                        String ordersTime = formatter.format(ordersList.get(j).getPayTime());
                        if (time.equals(ordersTime))
                        {
                            number++;
                        }
                    }
                }
            }
      integerList.add(number);
        }
        return integerList;
    }
}
